package org.ccay.excel.importer.validate.impl;
import org.ccay.core.util.StringUtil;
import org.ccay.excel.importer.validate.AbstractValidator;
import org.ccay.excel.importer.validate.IStatus;
/**
 * 
 * EXCEL导入模版整数据验证
 * @category：2012-7-21
 * @author chaowangbang
 * @version:
 * 
 */
public class IntegerValidator extends AbstractValidator{
	public static final String MESSAGE_KEY = "ccay.excel.validate.integer.error";
	/**
	 * 允许的值
	 */
	public IStatus doValidate(Object value) {
		if(null ==value || StringUtil.isNullOrEmpty(value.toString())) {
			return IStatus.Ok;	
		}
		try{
			int number = Integer.parseInt(value.toString());
			if(number <0){
				super.setMessageKey(MESSAGE_KEY);
				return error();
			}
		}catch(NumberFormatException ex){
			super.setMessageKey(MESSAGE_KEY);
			return error();
		}
		return IStatus.Ok;		
	}
}
